package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.dictionarydata.DictionaryCodeData;
import com.jinmdz.fmis.api.admin.model.dictionarydata.DictionaryDataSaveData;
import com.jinmdz.fmis.api.admin.model.dictionarydata.DictionaryListItem;
import com.jinmdz.fmis.api.admin.service.DictionaryDataService;
import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.dictionarydata.DictionaryDataListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 字典项目维护
 *
 * @author GuanKui
 * @date 2020/3/11 13:07
 */
@Api(description = "字典项目维护相关接口")
@RestController()
@RequestMapping("/admin/dictionary-data")
public class DictionaryDataController extends BaseController {

    @Resource
    private DictionaryDataService dictionaryDataService;

    /**
     * 加载字典类型信息列表
     *
     * @param
     * @return
     * @author GuanKui
     * @date 2020/3/9  15:05
     */
    @ApiOperation(value = "加载字典类型信息列表", notes = "字典类型，数据来自枚举类型【EDictCode】")
    @PostMapping("/load-dictionary-list")
    public BaseResult<ArrayList<DictionaryListItem>> loadDictionaryList() {
        return resultHandler(userItem -> dictionaryDataService.loadDictionaryList());
    }

    /**
     * 根据字典编码加载字典下的数据项列表
     *
     * @param data 字典类型数据
     * @return
     * @author GuanKui
     * @date 2020/3/11  14:30
     */
    @ApiOperation(value = "根据字典编码加载字典下的数据项列表", notes = "根据表【data_dictionary】中字典编码【dict_code】加载字典下的数据项列表")
    @PostMapping("/load-dictionary-data-list-with-code")
    public BaseResult<ArrayList<DictionaryDataListItem>> loadDictionaryDataListWithCode(@RequestBody DictionaryCodeData data) {
        return resultHandler(data, userItem -> dictionaryDataService.loadDictionaryDataListWithCode(data));
    }

    /**
     * 根据字典数据项目id，加载字典数据项基本信息
     *
     * @param data 主键
     * @return
     * @author GuanKui
     * @date 2020/3/11  14:30
     */
    @ApiOperation(value = "根据字典数据项目id，加载字典数据项基本信息", notes = "根据字典数据项目id，加载表【data_dictionary】字典数据项基本信息")
    @PostMapping("/load-dictionary-data-with-id")
    public BaseResult<DictionaryDataSaveData> loadDictionaryDataWithId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> dictionaryDataService.loadDictionaryDataWithId(data));
    }

    /**
     * 保存字典数据基本信息
     *
     * @param data 字典保存数据
     * @return
     * @author GuanKui
     * @date 2020/3/11  15:18
     */
    @ApiOperation(value = "保存字典数据基本信息", notes = "保存字典数据基本信息到表【data_dictionary】中")
    @PostMapping("/save-dictionary-data")
    public BaseResult saveDictionaryData(@RequestBody DictionaryDataSaveData data) {
        return resultHandler(data, userItem -> dictionaryDataService.saveDictionaryData(userItem, data));
    }

    /**
     * 删除字典数据项基本信息
     *
     * @param data 主键和数据版本
     * @return
     * @author GuanKui
     * @date 2020/3/11  15:08
     */
    @ApiOperation(value = "删除字典数据项基本信息", notes = "从表【data_dictionary】中删除字典数据信息")
    @PostMapping("/delete-dictionary-data-with-id")
    public BaseResult deleteDictionaryDataWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> dictionaryDataService.deleteDictionaryDataWithId(userItem, data));
    }

}

